$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'upk/upktradeorder/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'ID', width: 50, key: true },
			{ label: '支付流水ID，取值CATEGORY的ID(数字0：未插入)', name: 'payOrderId', index: 'PAY_ORDER_ID', width: 80 }, 			
			{ label: '交易子表流水ID，取值TRADE_SUB_ORDER的ID(数字0：未插入)', name: 'tradeSubGoodOrderId', index: 'TRADE_SUB_GOOD_ORDER_ID', width: 80 }, 			
			{ label: '交易关联商品快照流水ID，取值TRADE_GOODS的ID(数字0：未插入)', name: 'tradeGoodsId', index: 'TRADE_GOODS_ID', width: 80 }, 			
			{ label: '交易关联用户流水ID，取值USER的ID(数字0：未插入)', name: 'userId', index: 'USER_ID', width: 80 }, 			
			{ label: '用户选择的支付方式的ID,取值表PAY_TOOL表(数字0：未插入)', name: 'payToolId', index: 'PAY_TOOL_ID', width: 80 }, 			
			{ label: '收货人的姓名,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)', name: 'consignee', index: 'CONSIGNEE', width: 80 }, 			
			{ label: '收货人的固定电话,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)', name: 'tel', index: 'TEL', width: 80 }, 			
			{ label: '收货人的手机,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)', name: 'mobile', index: 'MOBILE', width: 80 }, 			
			{ label: '收货人的最佳送货时间,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)', name: 'bestTime', index: 'BEST_TIME', width: 80 }, 			
			{ label: '收货人的详细地址,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)', name: 'address', index: 'ADDRESS', width: 80 }, 			
			{ label: '用户选择的配送方式ID,取值表SHIPPING(字符串空：未插入)', name: 'shippingId', index: 'SHIPPING_ID', width: 80 }, 			
			{ label: '订单配送时间(数字0：未插入)', name: 'shippingTime', index: 'SHIPPING_TIME', width: 80 }, 			
			{ label: '订单附言,由用户提交订单前填写(字符串空：未插入)', name: 'postscript', index: 'POSTSCRIPT', width: 80 }, 			
			{ label: '订单应付款金额即商品总额加配送费加包装费等(数字0：未插入)', name: 'orderAmount', index: 'ORDER_AMOUNT', width: 80 }, 			
			{ label: '商品的总金额(数字0：未插入)', name: 'goodsAmount', index: 'GOODS_AMOUNT', width: 80 }, 			
			{ label: '配送费用即外卖系统比较重要(数字0：未插入)', name: 'shippingFee', index: 'SHIPPING_FEE', width: 80 }, 			
			{ label: '包装费用即点餐打包费外卖系统比较重要(数字0：未插入)', name: 'packFee', index: 'PACK_FEE', width: 80 }, 			
			{ label: '保价费用(数字0：未插入)', name: 'insureFee', index: 'INSURE_FEE', width: 80 }, 			
			{ label: '支付手续费用,跟支付方式的配置相关,取值表PAYMENT(数字0：未插入)', name: 'payFee', index: 'PAY_FEE', width: 80 }, 			
			{ label: '折扣总金额即积分和红包抵扣总额(数字0：未插入)', name: 'discount', index: 'DISCOUNT', width: 80 }, 			
			{ label: '消费积分数量，商品可用积分,用户拥有积分中最小者(数字0：未插入)', name: 'integral', index: 'INTEGRAL', width: 80 }, 			
			{ label: '使用消费积分金额抵扣的金额(数字0：未插入)', name: 'integralMoney', index: 'INTEGRAL_MONEY', width: 80 }, 			
			{ label: '优惠类型，即红包ID, USER_BONUS的BONUS_ID(数字0：未插入)', name: 'bonusId', index: 'BONUS_ID', width: 80 }, 			
			{ label: '优惠额度，使用红包抵扣的金额(数字0：未插入)', name: 'bonusMoney', index: 'BONUS_MONEY', width: 80 }, 			
			{ label: '使用用户余额抵扣的金额，取用户设定余额,用户可用余额,订单金额中最小者(数字0：未插入)', name: 'balanceMoney', index: 'BALANCE_MONEY', width: 80 }, 			
			{ label: '需付款金额即减去优惠总金额后剩余的金额(数字0：未插入)', name: 'moneyPaid', index: 'MONEY_PAID', width: 80 }, 			
			{ label: '订单状态(数字0：未插入，1已确认; 2已取消; 3无效; 4退货)', name: 'orderStatus', index: 'ORDER_STATUS', width: 80 }, 			
			{ label: '订单总评分(数字0：未插入)', name: 'orderScore', index: 'ORDER_SCORE', width: 80 }, 			
			{ label: '操作员(字符串空：未插入)', name: 'operator', index: 'OPERATOR', width: 80 }, 			
			{ label: '创建即上传时间(数字0：未插入)', name: 'createUtc', index: 'CREATE_UTC', width: 80 }, 			
			{ label: '修改即更新时间(数字0：未插入)', name: 'modifyUtc', index: 'MODIFY_UTC', width: 80 }, 			
			{ label: '是否删除(数字0：未插入，1.未删除,2：删除，)', name: 'isDeleted', index: 'IS_DELETED', width: 80 }, 			
			{ label: '版本号(数字0：未插入)', name: 'version', index: 'VERSION', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		upkTradeOrder: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.upkTradeOrder = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.upkTradeOrder.id == null ? "upk/upktradeorder/save" : "upk/upktradeorder/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.upkTradeOrder),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "upk/upktradeorder/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "upk/upktradeorder/info/"+id, function(r){
                vm.upkTradeOrder = r.upkTradeOrder;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});